package com.fcdream.brpg.weixin.worker;

import com.fcdream.brpg.weixin.worker.text.BaseTextMsgWorker;
import com.jfinal.weixin.sdk.msg.in.InTextMsg;

import java.util.HashMap;

/**
 * Created by shmdu on 2016/6/12.
 */
public class MsgWorkerFactory {

    private static final HashMap<String, Class<? extends MsgWorkerIface>> FACTORY_MAP = new HashMap<>();

    static {

    }

    public BaseTextMsgWorker createWorker(InTextMsg inTextMsg) {
        String msg = inTextMsg.getContent().trim();
        Class iface = FACTORY_MAP.get(msg);
        BaseTextMsgWorker worker = null;
        if (iface != null) {
            try {
                worker = (BaseTextMsgWorker) iface.newInstance();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        if (worker != null) {
            return worker;
        }
        return null;
    }
}
